package com.itheima.reggie.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyMetaObjecthandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        //获取用户id
        Long userId = BaseContext.threadLocal.get();
        System.out.println("我执行了insertFill.....");
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("createUser", userId);
        metaObject.setValue("updateUser", userId);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //获取用户id
        Long userId = BaseContext.threadLocal.get();
        System.out.println("我执行了updateFill.....");
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser", userId);
    }
}
